﻿namespace MyCoreLib.Automation.Data.SqlClient.Model
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;

    public class StoredProcedureInfo
    {
        public readonly string Name;
        public readonly string Schema;
        public readonly string FullName;
        public readonly ReadOnlyCollection<ContractInfo> Contracts;        

        public StoredProcedureInfo(IOutput output, StoredProcedureSelectorInfo selectorInfo, Dictionary<string, ContractInfo> ixContractByName)
        {
            Name = selectorInfo.Name;
            Schema = selectorInfo.Schema;
            FullName = selectorInfo.FullName;

            var list = new List<ContractInfo>();
            foreach (var contractName in selectorInfo.ResultSetContractNames)
            {
                if (ixContractByName.ContainsKey(contractName))
                {
                    list.Add(ixContractByName[contractName]);
                }
            }
            Contracts = new ReadOnlyCollection<ContractInfo>(list);
        }
    }
}
